﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CashFlow.Entities.Models;
using System.ComponentModel.DataAnnotations;
using Should.Fluent;

namespace CashFlow.Web.Tests.Models
{
	[TestClass]
	public class BillModelTest
	{
		[TestMethod]
		public void Setting_LastDate_Prior_To_FirstDate_Yeilds_Error()
		{
			var model = new BillModel
			{
				PayeeName = "name",
				FirstDate = DateTime.Now,
				LastDate = DateTime.Now.AddDays(-1)
			};
			var validationContext = new ValidationContext(model, null, null);

			var result = model.Validate(validationContext);

			result.Should().Not.Be.Null();
			var errorMessage = result.First().ErrorMessage;
			errorMessage.Should().Equal(CashFlow.Entities.Properties.Resources.ErrorLastDateGTFirstDate);
			var field = result.First().MemberNames.First();
			field.Should().Equal("LastDate");
		}

		[TestMethod]
		public void Empty_LastDate_DoesNot_Yeilds_Error()
		{
			var model = new BillModel
			{
				PayeeName = "name",
				FirstDate = DateTime.Now
			};
			var validationContext = new ValidationContext(model, null, null);

			var result = model.Validate(validationContext);

			result.FirstOrDefault().Should().Be.Null();
		}
	}
}
